//
//  WeiChatManager.m
//  PropertyManager
//
//  Created by TNG on 2018/8/27.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "WeiChatManager.h"
#import <WebKit/WebKit.h>

@implementation WeiChatManager

+(instancetype)shareManager
{
    static WeiChatManager * manager;
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        manager = [[WeiChatManager alloc] init];
    });
    return manager;
}

-(void)onResp:(BaseResp *)resp
{
    if([resp isKindOfClass:[SendAuthResp class]]) {
        switch (resp.errCode) {
            case WXSuccess:
            {
#warning 接口登录
                NSMutableDictionary * params = [NSMutableDictionary dictionary];
                [params setValue:@"0" forKey:@"code"];
                [[HTTPClient shareClient] requestWithPath:@"/rest/wxLoginController" AndParams:params AndReturnBlock:^(NSDictionary *dic) {
                    
                } AndFailMessage:^(NSString *message, NSString *errorCode) {
                    
                }];
//                SendAuthResp * s = (SendAuthResp *)resp;
                NSSLog(@"登录成功=== ");
//                NSMutableDictionary * params = [NSMutableDictionary dictionary];
//                [params setValue:@"wx11a74c7abdcc0d79" forKey:@"appid"];
//                [params setValue:@"0b505fecb987e5bf4dda4767754fb233" forKey:@"secret"];
//                [params setValue:s.code forKey:@"code"];
//                [params setValue:@"authorization_code" forKey:@"grant_type"];
//                WeakSelf;
//                [[TNGHTTP shareHttpClient] POST:@"https://api.weixin.qq.com/sns/oauth2/access_token" parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
//
//                } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//                    NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//                    NSString * access_token = dic[@"access_token"];
//                    NSString * expires_in = dic[@"expires_in"];
//                    NSString * openID = dic[@"openid"];
//                    NSString * refresh_token = dic[@"refresh_token"];
//                    NSString * scope = dic[@"scope"];
//                    NSString * unionid = dic[@"unionid"];
//
//                    NSMutableDictionary * paramss = [NSMutableDictionary dictionary];
//                    [paramss setValue:access_token forKey:@"access_token"];
//                    [paramss setValue:refresh_token forKey:@"refresh_token"];
//                    [paramss setValue:openID forKey:@"openid"];
//                    [paramss setValue:expires_in forKey:@"expires_in"];
//                    [paramss setValue:scope forKey:@"scope"];
//                    [paramss setValue:unionid forKey:@"unionid"];
//
//                    [[TNGHTTP shareHttpClient] POST:@"https://api.weixin.qq.com/sns/userinfo" parameters:paramss progress:^(NSProgress * _Nonnull uploadProgress) {
//                    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//                        NSDictionary * dicc = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//                        NSSLog(@"dic=== %@",dicc);
//                        weakSelf.WeiChatDidLoginBlock();
//                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//
//                    }];
//                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//
//                }];
            }
                break;
            case WXErrCodeAuthDeny:
            {
                NSSLog(@"授权失败=== ");
            }
                break;
            case WXErrCodeUserCancel:
            {
                NSSLog(@"用户点击取消并返回===");
            }
                break;
            default:
                break;
        }
    }else if ([resp isKindOfClass:[PayResp class]])
    {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"weiXinPayDidBack" object:nil userInfo:@{@"code":[NSString stringWithFormat:@"%d",resp.errCode]}];
    }else
    {
        
    }
}

@end
